let searchBtn = document.querySelector('#search-btn');
let searchBar = document.querySelector('.search-bar-container');
let formBtn = document.querySelector('#login-btn');
let loginForm = document.querySelector('.login-form-container');
let formClose = document.querySelector('#form-close');
let menu = document.querySelector('#menu-bar');
let navbar = document.querySelector('.navbar');
let videoBtn = document.querySelectorAll('.vid-btn');
let myRegister = document.getElementById('myRegister');
let boxList = document.querySelectorAll('.box-container .box');
boxList.forEach(box => {
    box.addEventListener('click', (e) => {
        if (e.target.closest('.btn')) return;
        
        let to = box.getAttribute('to');
        console.log(to);
        //跳转to属性对应的页面
        window.location.href = to;
    });
});
//判断是否登录
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
if (currentUser) {  
    // 如果用户已登录，显示我的预约按钮
    myRegister.style.opacity = '1';
    console.log("显示我的预约按钮");
    
}
window.onscroll = () => {
    searchBtn.classList.remove('fa-times');
    searchBar.classList.remove('active');
    menu.classList.remove('fa-times');
    navbar.classList.remove('active');
    loginForm.classList.remove('active');
}

menu.addEventListener('click', () => {
    menu.classList.toggle('fa-times');
    navbar.classList.toggle('active');
});

searchBtn.addEventListener('click', () => {
    searchBtn.classList.toggle('fa-times');
    searchBar.classList.toggle('active');
});



//点击登录按钮让登录表单显示
formBtn.addEventListener('click', () => {
    console.log('Login button clicked');
    loginForm.classList.add('active');
});
//点击关闭按钮让登录表单隐藏
formClose.addEventListener('click', () => {
    console.log('Close button clicked');
    loginForm.classList.remove('active');
});

//给轮播视频按钮添加点击事件
videoBtn.forEach(btn => {
    btn.addEventListener('click', () => {
        //选中当前激活的按钮并移除 active 类
        document.querySelector('.controls .active').classList.remove('active');
        btn.classList.add('active');
        // getAttribute获取链接的 target 属性值
        let src = btn.getAttribute('data-src');
        //更换视频
        document.querySelector('#video-slider').src = src;
    });
});

var swiper = new Swiper(".review-slider", {
    spaceBetween: 20,
    loop: true,
    autoplay: {
        delay: 2500,
        disableOnInteraction: false,
    },
    breakpoints: {
        640: {
            slidesPerView: 1,
        },
        768: {
            slidesPerView: 2,
        },
        1024: {
            slidesPerView: 3,
        },
    },

    effect: 'coverflow',  // 3D流效果
    coverflowEffect: {
        rotate: 50,
        slideShadows: false,
    },
});


var swiper = new Swiper(".brand-slider", {
    spaceBetween: 20,
    loop: true,
    autoplay: {
        delay: 2500,
        disableOnInteraction: false,
    },
    breakpoints: {
        450: {
            slidesPerView: 2,
        },
        768: {
            slidesPerView: 3,
        },
        991: {
            slidesPerView: 4,
        },
        1200: {
            slidesPerView: 5,
        },
    },
});

